package cn.hiapi.shopkeeper.service.order;

import cn.hiapi.basic.jpa.pageable.QueryWrapper;
import cn.hiapi.basic.service.AbsBasicService;
import cn.hiapi.shopkeeper.entity.order.ActivityVoteOrder;
import cn.hiapi.shopkeeper.jpa.order.ActivityVoteOrderJpa;
import com.alibaba.fastjson.JSONObject;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author AdinZ
 * @date 2023/2/3 22:54
 */
@Service
public class ActivityVoteOrderService extends AbsBasicService<ActivityVoteOrderJpa, ActivityVoteOrder, Long> {

    /**
     * 投票排行榜
     * @param aid
     * @return
     */
    public List<JSONObject> activityRank(long aid) {
        return this.repository.activityRank(aid);
    }

    /**
     * 验证投票次数
     *
     * @param aid     活动id
     * @param uid     用户id
     * @param otherId 投票选项
     * @return
     */
    public long existsVote(long aid, long uid, long otherId) {
        return this.count(new QueryWrapper().eq("aid", aid).eq("uid", uid).eq("otherId", otherId));
    }
}
